package com.tlibrary.util;

import org.springframework.stereotype.Service;

/**
 * @Author：wcc
 * @Description：
 * @Date：Create in: 2019/1/31--16:37
 */
@Service
public class ShowpaperUtil {

    /**
     * 一个选项或标题
     * @param a
     * @return
     */

    //判断是否为空
    //判断需要替换几次图片
    //得到图片标签
    //去掉字符串中的图片
    public boolean isExitpic(String a) {
        {
            int img=0;
            img = getCount(a , "img");
            if (0==img){
                return false;
            }
            else {
                return true;
            }

        }
    }

    private int getCount(String text,String tag){
        int count=0;
        String aim="</"+tag;
        char[] texts = text.toCharArray();
        char[] aims = aim.toCharArray();
        for (int i = 0; i <texts.length ; i++) {
            if (texts[i]==aims[0]){
                for (int j = 1; j <aims.length ; j++) {
                    if (texts[i+j]!=aims[j]){
                        break;
                    }else if (j==(aims.length-1)){
                        count++;
                    }
                }
            }
        }
        return count;
    }

    public String getTab(String s) {
        int i = s.indexOf("src=");
        int star=s.indexOf("'",i);
        int end=s.indexOf("'",star+1);
        String substring = s.substring(star+1, end);
        return substring;
    }

    public String removeTab(String s){
        int star = s.indexOf("</img");
        int end=s.indexOf("'/>",star+1);
        String starstring = s.substring(0,star);
        String endstring = s.substring(end+1);
        System.out.println(starstring);
        System.out.println(endstring);
        return  "";
    }

}
